package com.rickpan.dto.response;

import com.rickpan.entity.TransferRecord;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 传输记录DTO
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class TransferRecordDTO {
    
    private Long id;
    private String fileName;
    private String originalName;
    private Long fileSize;
    private String fileType;
    private String transferType;
    private String transferStatus;
    private BigDecimal progressPercentage;
    private Long transferredBytes;
    private Long transferSpeed;
    
    private String startTime;
    private String endTime;
    private String errorMessage;
    private String filePath;
    private Long parentFolderId;
    private String createdAt;
    private String updatedAt;

    // 构造函数
    public TransferRecordDTO() {}

    // 时间格式化器
    private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    // 从Entity转换的静态方法
    public static TransferRecordDTO from(TransferRecord record) {
        TransferRecordDTO dto = new TransferRecordDTO();
        dto.setId(record.getId());
        dto.setFileName(record.getFileName());
        dto.setOriginalName(record.getOriginalName());
        dto.setFileSize(record.getFileSize());
        dto.setFileType(record.getFileType() != null ? record.getFileType().name() : null);
        dto.setTransferType(record.getTransferType() != null ? record.getTransferType().name() : null);
        dto.setTransferStatus(record.getTransferStatus() != null ? record.getTransferStatus().name() : null);
        dto.setProgressPercentage(record.getProgressPercentage());
        dto.setTransferredBytes(record.getTransferredBytes());
        dto.setTransferSpeed(record.getTransferSpeed());

        // 格式化时间字段
        dto.setStartTime(record.getStartTime() != null ? record.getStartTime().format(TIME_FORMATTER) : null);
        dto.setEndTime(record.getEndTime() != null ? record.getEndTime().format(TIME_FORMATTER) : null);
        dto.setCreatedAt(record.getCreatedAt() != null ? record.getCreatedAt().format(TIME_FORMATTER) : null);
        dto.setUpdatedAt(record.getUpdatedAt() != null ? record.getUpdatedAt().format(TIME_FORMATTER) : null);

        dto.setErrorMessage(record.getErrorMessage());
        dto.setFilePath(record.getFilePath());
        dto.setParentFolderId(record.getParentFolderId());
        return dto;
    }

    // Getter和Setter方法
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getOriginalName() {
        return originalName;
    }

    public void setOriginalName(String originalName) {
        this.originalName = originalName;
    }

    public Long getFileSize() {
        return fileSize;
    }

    public void setFileSize(Long fileSize) {
        this.fileSize = fileSize;
    }

    public String getFileType() {
        return fileType;
    }

    public void setFileType(String fileType) {
        this.fileType = fileType;
    }

    public String getTransferType() {
        return transferType;
    }

    public void setTransferType(String transferType) {
        this.transferType = transferType;
    }

    public String getTransferStatus() {
        return transferStatus;
    }

    public void setTransferStatus(String transferStatus) {
        this.transferStatus = transferStatus;
    }

    public BigDecimal getProgressPercentage() {
        return progressPercentage;
    }

    public void setProgressPercentage(BigDecimal progressPercentage) {
        this.progressPercentage = progressPercentage;
    }

    public Long getTransferredBytes() {
        return transferredBytes;
    }

    public void setTransferredBytes(Long transferredBytes) {
        this.transferredBytes = transferredBytes;
    }

    public Long getTransferSpeed() {
        return transferSpeed;
    }

    public void setTransferSpeed(Long transferSpeed) {
        this.transferSpeed = transferSpeed;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public Long getParentFolderId() {
        return parentFolderId;
    }

    public void setParentFolderId(Long parentFolderId) {
        this.parentFolderId = parentFolderId;
    }

    public String getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }

    public String getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(String updatedAt) {
        this.updatedAt = updatedAt;
    }
}
